package com.bsb.biz.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.bsb.base.common.util.StringUtils;
import com.bsb.base.mapper.BsbCategoryMapper;
import com.bsb.base.model.BsbCategory;
import com.bsb.base.model.BsbCategoryExample;
import com.bsb.base.model.BsbCategoryExample.Criteria;

@Service
public class BsbCategoryService{
	
	@Resource
	private BsbCategoryMapper bsbCategoryMapper;
	
	public String getCategoryName(String uuid){
		if(StringUtils.isEmpty(uuid)){
			return null;
		}
		 BsbCategory bsbCategoryByUuid = bsbCategoryMapper.selectByPrimaryKey(uuid);
		 if(null != bsbCategoryByUuid){
			 return bsbCategoryByUuid.getName();
		 }
		return null;
	}
	
	public List<BsbCategory> childList(String pid){
		if(StringUtils.isEmpty(pid)){
			return null;
		}
		BsbCategoryExample example = new BsbCategoryExample();
		Criteria criteria = example.createCriteria();
		criteria.andPidEqualTo(pid);
		List<BsbCategory> list = bsbCategoryMapper.selectByExample(example );
		return list;
	}
	
	public void addBsbCategory(BsbCategory bsbCategory) {
		bsbCategoryMapper.insertSelective(bsbCategory);
	}
	
	public void delBsbCategoryByUuid(String uuid) {
		bsbCategoryMapper.deleteByPrimaryKey(uuid);
	}
	
	public void updateBsbCategory(BsbCategory bsbCategory) {
		bsbCategoryMapper.updateByPrimaryKeySelective(bsbCategory);
	}
	
	public void updateBsbCategoryByExample(BsbCategory bsbCategory,BsbCategoryExample bsbCategoryExample){
	    bsbCategoryMapper.updateByExampleSelective(bsbCategory,bsbCategoryExample);
	}
	
	public BsbCategory getBsbCategoryByUuid(String uuid) {
		return bsbCategoryMapper.selectByPrimaryKey(uuid);
	}
	
	public List<BsbCategory> getPageBsbCategory(BsbCategoryExample bsbCategoryExample) {
		return bsbCategoryMapper.selectPage(bsbCategoryExample);
	}
	
	public int countBsbCategory(BsbCategoryExample bsbCategoryExample) {
		return bsbCategoryMapper.countByExample(bsbCategoryExample);
	}
	
	public List<BsbCategory> selectByExample(BsbCategoryExample example){
	    return bsbCategoryMapper.selectByExample(example);
	}
}
